import 'package:flutter/material.dart';
import 'package:search_people/entrance/route/routes.dart';
import 'package:search_people/utils/ali_login.dart';
import 'package:search_people/utils/component/component.dart';
import 'package:search_people/utils/fluwx_util.dart';
import 'package:search_people/utils/share/share_util.dart';
import 'package:search_people/value/topcolors.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../utils/util.dart';
import 'logic.dart';

class PasswordloginPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final logic = Get.put(PasswordloginLogic());
    final state = Get.find<PasswordloginLogic>().state;

    return Scaffold(
      backgroundColor: Colors.white,
      body: GetBuilder<PasswordloginLogic>(
        builder: (logic) {
          return Column(
            children: [
              SafeArea(
                  child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  GestureDetector(
                    child: Padding(
                      padding: EdgeInsets.fromLTRB(15.r, 20.r, 30.r, 25.r),
                      child: Image.asset(
                        'assets/images/x.png',
                        width: 18.r,
                        height: 18.r,
                      ),
                    ),
                    onTap: () {
                      Get.back();
                    },
                  ),
                  TextButton(
                      onPressed: () {
                        logic.changeLoginType();
                      },
                      child: Text(
                        state.loginType == 1 ? '切换验证码登录' : '切换密码登录',
                        style: TextStyle(
                            color: TopColors.black_66, fontSize: 15.r),
                      ))
                ],
              )),
              SizedBox(
                  height: state.loginType == 1 ? 275.r : 235.r,
                  child: PageView(
                    controller: state.pageController,
                    physics: const NeverScrollableScrollPhysics(),
                    children: [
                      Column(
                        children: [
                          Container(
                            margin: EdgeInsets.only(top: 30.r, bottom: 45.r),
                            child: Text(
                              '验证码登录',
                              style: TextStyle(
                                  color: TopColors.black_33, fontSize: 24.sp),
                            ),
                          ),
                          Container(
                            margin: EdgeInsets.only(left: 35.r, right: 35.r),
                            child: TextField(
                              controller: state.nameCotroller,
                              decoration: InputDecoration(
                                border: InputBorder.none,
                                hintText: '请输入手机号',
                                hintStyle: TextStyle(
                                    fontSize: 16.sp, color: TopColors.black_99),
                              ),
                            ),
                          ),
                          Container(
                            color: TopColors.black_dd,
                            height: 0.5,
                            margin: EdgeInsets.fromLTRB(30.r, 5.r, 30.w, 15.r),
                          ),
                          Container(
                            margin: EdgeInsets.only(left: 30.r, right: 30.r),
                            child: CodeField(
                              controller: state.smsCotroller,
                              smsClickListener: logic.sendSms,
                            ),
                          ),
                        ],
                      ),
                      Column(
                        children: [
                          Container(
                            margin: EdgeInsets.only(top: 30.r, bottom: 45.r),
                            child: Text(
                              '密码登录',
                              style: TextStyle(
                                  color: TopColors.black_33, fontSize: 24.sp),
                            ),
                          ),
                          Container(
                            margin: EdgeInsets.only(left: 35.r, right: 35.r),
                            child: TextField(
                              controller: state.nameCotroller,
                              decoration: InputDecoration(
                                border: InputBorder.none,
                                hintText: '请输入账号',
                                hintStyle: TextStyle(
                                    fontSize: 16.sp, color: TopColors.black_99),
                              ),
                            ),
                          ),
                          Container(
                            color: TopColors.black_dd,
                            height: 0.5,
                            margin: EdgeInsets.fromLTRB(30.r, 5.r, 30.w, 15.r),
                          ),
                          Container(
                            margin: EdgeInsets.only(left: 35.r, right: 35.r),
                            child: TextField(
                              controller: state.passCotroller,
                              obscureText: !state.isShow,
                              decoration: InputDecoration(
                                  border: InputBorder.none,
                                  hintText: '请填写密码',
                                  hintStyle: TextStyle(
                                      fontSize: 16.sp,
                                      color: TopColors.black_99),
                                  suffixIcon: GestureDetector(
                                      onTap: logic.fixPasswordText,
                                      child: Container(
                                        padding: EdgeInsets.all(15.r),
                                        child: Image.asset(
                                          state.isShow
                                              ? 'assets/images/eye_open.png'
                                              : 'assets/images/eye_close.png',
                                          fit: BoxFit.fitWidth,
                                          width: 5,
                                          height: 5,
                                        ),
                                      ))),
                            ),
                          ),
                          Container(
                            color: TopColors.black_dd,
                            height: 0.5,
                            margin: EdgeInsets.fromLTRB(30.w, 5.r, 30.w, 18.r),
                          ),
                          Container(
                            margin: EdgeInsets.symmetric(horizontal: 30.r),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                GestureDetector(
                                  onTap: () =>
                                      Get.toNamed(RouterPath.registerPage),
                                  child: Text(
                                    '注册账号',
                                    style: TextStyle(
                                        color: TopColors.main_color,
                                        fontSize: 13.r),
                                  ),
                                ),
                                GestureDetector(
                                  onTap: () => Get.toNamed(
                                      RouterPath.forgetpasswordPage),
                                  child: Text(
                                    '忘记密码？',
                                    style: TextStyle(
                                        color: TopColors.main_color,
                                        fontSize: 13.r),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ],
                  )),
              GestureDetector(
                  child: Container(
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.all(Radius.circular(5.r)),
                        color: TopColors.main_color),
                    padding: EdgeInsets.all(12.r),
                    margin: EdgeInsets.fromLTRB(20.r, 30.r, 20.w, 20.r),
                    child: Center(
                      child: Text(
                        '登录',
                        style: TextStyle(color: Colors.white, fontSize: 18.sp),
                      ),
                    ),
                  ),
                  onTap: () {
                    logic.login();

                    // TopImModule.init('857751635#mychat');
                    // TopImModule.joinSingleRoom();
                  }),
              BrnCheckbox(
                radioIndex: 0,
                // isSelected: controller.state.isAgree,
                childOnRight: true,
                mainAxisSize: MainAxisSize.min,
                child: Row(
                  children: [
                    Text('登录即同意',
                        style: TextStyle(
                            color: const Color.fromRGBO(0, 0, 0, 0.6),
                            fontSize: 14.sp)),
                    GestureDetector(
                      child: Text('《用户协议》',
                          style: TextStyle(
                              color: TopColors.main_color, fontSize: 14.sp)),
                      onTap: () {
                        // Get.to(
                        //         () => H5Page('用户协议', UrlPath.userAgreementUrl));
                      },
                    ),
                    Text('和',
                        style: TextStyle(
                            color: const Color.fromRGBO(0, 0, 0, 0.6),
                            fontSize: 14.sp)),
                    GestureDetector(
                      child: Text('《隐私政策》',
                          style: TextStyle(
                              color: TopColors.main_color, fontSize: 14.sp)),
                      onTap: () {
                        // Get.to(() =>
                        //     H5Page('隐私政策', UrlPath.privacyAgreementUrl));
                      },
                    ),
                  ],
                ),
                onValueChangedAtIndex: (index, value) {
                  // controller.state.isAgree = !controller.state.isAgree;
                },
              ),
            ],
          );
        },
      ),
    );
  }

  Widget getLoginItem({
    required String icon,
    required String name,
    required VoidCallback onTap,
  }) {
    return InkWell(
      onTap: onTap,
      child: Column(
        children: [
          Image.asset(
            icon,
            width: 40,
            height: 40,
          ),
          Container(
            margin: EdgeInsets.fromLTRB(28.r, 12.5.r, 28.r, 0),
            // margin: const EdgeInsets.only(top: 12.5),
            child: Text(
              name,
              style: TextStyle(color: TopColors.black_66, fontSize: 13.sp),
            ),
          )
        ],
      ),
    );
  }
}
